package org.me.marble;

import android.view.*;
import android.widget.*;
import android.graphics.*;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;

/**
 * 
 * @author tungi
 */

public class StartActivity extends Activity{
	
	@Override
	public void onCreate(Bundle icycle){
		super.onCreate(icycle);
        getWindow().setBackgroundDrawable(new BackgroundImage(this,
                R.drawable.background_main3,Color.BLACK,0.5,0.5).getCurrent());
        getWindow().setFormat(PixelFormat.RGBA_8888);
        
        setContentView(R.layout.start);
        
        ImageButton button;
        button=(ImageButton)findViewById(R.buttons.levelleftclick);
        button.setBackgroundColor(Color.TRANSPARENT);
        if(OptionsLibrary.difficulty_level==1)
        	button.setEnabled(false);
        
        button=(ImageButton)findViewById(R.buttons.levelrightclick);
        button.setBackgroundColor(Color.TRANSPARENT);
        if(OptionsLibrary.difficulty_level==OptionsLibrary.MAX_DIFFICULTY)
        	button.setEnabled(false);
        
        button=(ImageButton)findViewById(R.buttons.modeleftclick);
        button.setBackgroundColor(Color.TRANSPARENT);
        if(OptionsLibrary.game_type.equals("normal"))
        	button.setEnabled(false);
        
        button=(ImageButton)findViewById(R.buttons.moderightclick);
        button.setBackgroundColor(Color.TRANSPARENT);
        if(OptionsLibrary.game_type.equals("time"))
        	button.setEnabled(false);
        
        button=(ImageButton)findViewById(R.buttons.btnstart);
        button.setBackgroundColor(Color.TRANSPARENT);

        TextView tv=(TextView)findViewById(R.text.modetext);
        if(OptionsLibrary.game_type.equals("normal"))
        	tv.setText("Normal");
        else if(OptionsLibrary.game_type.equals("point"))
        	tv.setText("Point Saving");
        else if(OptionsLibrary.game_type.equals("time"))
        	tv.setText("Time Challenge");
        
        tv=(TextView)findViewById(R.text.leveltext);
        tv.setText("Level "+Integer.toString(OptionsLibrary.difficulty_level));
	}
	
	public void onClick(View v){		
		switch(v.getId()){
			case R.buttons.levelleftclick:{
				TextView tv=(TextView)findViewById(R.text.leveltext);
				OptionsLibrary.difficulty_level--;
				tv.setText("Level "+Integer.toString(OptionsLibrary.difficulty_level));
				if(OptionsLibrary.difficulty_level==1)
					((ImageButton)findViewById(R.buttons.levelleftclick)).setEnabled(false);
				else if(OptionsLibrary.difficulty_level==OptionsLibrary.MAX_DIFFICULTY-1)
					((ImageButton)findViewById(R.buttons.levelrightclick)).setEnabled(true);
			}break;
			case R.buttons.levelrightclick:{
				TextView tv=(TextView)findViewById(R.text.leveltext);
				OptionsLibrary.difficulty_level++;
				tv.setText("Level "+Integer.toString(OptionsLibrary.difficulty_level));
				if(OptionsLibrary.difficulty_level==2)
					((ImageButton)findViewById(R.buttons.levelleftclick)).setEnabled(true);
				else if(OptionsLibrary.difficulty_level==OptionsLibrary.MAX_DIFFICULTY)
					((ImageButton)findViewById(R.buttons.levelrightclick)).setEnabled(false);
			}break;
			case R.buttons.modeleftclick:{
				TextView tv=(TextView)findViewById(R.text.modetext);
				if(OptionsLibrary.game_type.equals("point")){
					tv.setText("Normal");
					OptionsLibrary.game_type="normal";
					((ImageButton)findViewById(R.buttons.modeleftclick)).setEnabled(false);
					((ImageButton)findViewById(R.buttons.moderightclick)).setEnabled(true);
				}
				else if(OptionsLibrary.game_type.equals("time")){
					tv.setText("Point Saving");
					OptionsLibrary.game_type="point";
					((ImageButton)findViewById(R.buttons.moderightclick)).setEnabled(true);
				}
			}break;
			case R.buttons.moderightclick:{
				TextView tv=(TextView)findViewById(R.text.modetext);
				if(OptionsLibrary.game_type.equals("point")){
					tv.setText("Time Challenge");
					OptionsLibrary.game_type="time";
					((ImageButton)findViewById(R.buttons.moderightclick)).setEnabled(false);
				}
				else if(OptionsLibrary.game_type.equals("normal")){
					tv.setText("Point Saving");
					OptionsLibrary.game_type="point";
					((ImageButton)findViewById(R.buttons.modeleftclick)).setEnabled(true);
				}
			}break;
			case R.buttons.btnstart:{
	            OptionsLibrary.started=true;
	            finish();
	            Intent intent=new Intent(this,GameActivity.class);
	            startActivity(intent);
			}break;
			default:break;
		}
	}
}
